#include <stdio.h>
#include "./include/import.h"
//#include "./include/PDF2BinConvert.h"
#include <iostream>
//#include "PDF2Bin.h"
using namespace std;

int main(int argc, char** argv)
{
	//FX_INT32 nAnnotCount = 1;
	

	wchar_t csSrcPath[] = L"./pdfs/test.pdf";
	wchar_t csDestPath[] = L"./pdfs/data/dest.pdf";
	
	PDF2PDFMoudleMgr mgr = FP2P_CreateModuleMgr();

	cout << "--->New Processor" << endl;
	PDF2PDFProcessor processor = FP2P_NewProcessor();
	cout << "--->End Processor" << endl;
	cout << "--->Start Extract" << endl;
	int nRel = FP2P_StartExtract(processor, csSrcPath, "");
	if(nRel != 0)
	{
		cout << "--->End Extract with Erro" << endl;
		return 0;
	}
		
	cout << "--->End Extract" << endl;
	int nPage = FP2P_CountPage(processor);
	cout << nPage << endl;
for(int iPage=0; iPage<nPage; iPage++)
{
//cout << "--->Start CountParagraph" << endl;
	int nPara = FP2P_CountParagraph(processor, iPage);

	for(int i=0; i<nPara; i++)
	{

			if(FP2P_IsAllLineIsIndepend(processor, iPage, i))
			{

				int nLine = FP2P_CountIndependLineInParagraph(processor, iPage, i);
				for(int j=0; j<nLine; j++)
				{
					PDFWStringContent lineCon = FP2P_GetIndependLineContent(processor, iPage, i, j);
					int nLen = 0;
					const wchar_t* lpszCon = FP2P_GetContent(lineCon, nLen);
					if(lpszCon)
					{
						wcout<<lpszCon<<endl;
					}

					FP2P_AddIndependLine(processor, iPage, i, j, lpszCon);

					FP2P_FreeContent(lineCon);
				}
	
			}else{
				
				PDFWStringContent con = FP2P_GetParagraphContent(processor, iPage, i);
				
				int nLen = 0;
			
				const wchar_t* lpszCon = FP2P_GetContent(con, nLen);
	
				if(lpszCon)
				{
				//	wcout<<lpszCon<<endl;
				}

				FP2P_AddParagraph(processor, iPage, i, lpszCon);
				FP2P_FreeContent(con);
			}
	
	}
}	
		

	int n = FP2P_SaveFile(processor, csDestPath);

	cout << "--->Start FP2P_CloseProcessor" << endl;
	FP2P_CloseProcessor(processor);
	cout << "--->End FP2P_CloseProcessor" << endl;

	FP2P_DestroyModuleMgr(mgr);
	return 0;
}
